---
title: "Summary-Stats-Intercorrelations"
author: "Ragini Srinivasan"
date: "7/24/2021"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown: Table A6.4 (Summary Statistics and Table of Intercorrelations)

```{r}
# Load the data
final_lebensraum_data <- read_csv("final-lebensraum-data.csv")
```

```{r}
# Change variables to numeric if necessary
final_lebensraum_data$total_tb_death_1914 <- as.numeric(as.character(final_lebensraum_data$total_tb_death_1914))
final_lebensraum_data$total_tb_death_1918 <- as.numeric(as.character(final_lebensraum_data$total_tb_death_1918))
```

```{r}
# Create a correlation matrix
nazi_data_voting_and_joinership <-
  final_lebensraum_data %>% select("total_joiners_per_1000", "war_baby_joiners_per_1000", "war_baby_out_of_total_joiners", "prop_vote_1928", "prop_vote_1930", "change_votes",
                               "total_tb_death_1914", "total_tb_death_1918", "ratio_mort_tb")
correlation_matrix <- cor(nazi_data_voting_and_joinership, use = "pairwise.complete.obs")
correlation_matrix
```

```{r}
# Calculate all summary statistics of important variables
summary_stats <- data.frame(
  
  variable = c("total_joiners_per_1000", "war_baby_joiners_per_1000", "war_baby_out_of_total_joiners",
               "prop_vote_1928", "prop_vote_1930", "change_votes", 
               "total_tb_death_1914", "total_tb_death_1918", "ratio_mort_tb"),
  
  mean = c(mean(nazi_data_voting_and_joinership$total_joiners_per_1000, na.rm = TRUE),
           mean(nazi_data_voting_and_joinership$war_baby_joiners_per_1000, na.rm = TRUE),
           mean(nazi_data_voting_and_joinership$war_baby_out_of_total_joiners, na.rm = TRUE),
           mean(nazi_data_voting_and_joinership$prop_vote_1928),
           mean(nazi_data_voting_and_joinership$prop_vote_1930),
           mean(nazi_data_voting_and_joinership$change_votes),
           mean(nazi_data_voting_and_joinership$total_tb_death_1914, na.rm = TRUE),
           mean(nazi_data_voting_and_joinership$total_tb_death_1918, na.rm = TRUE),
           mean(nazi_data_voting_and_joinership$ratio_mort_tb, na.rm = TRUE)),
  
  median = c(median(nazi_data_voting_and_joinership$total_joiners_per_1000, na.rm = TRUE),
             median(nazi_data_voting_and_joinership$war_baby_joiners_per_1000, na.rm = TRUE),
             median(nazi_data_voting_and_joinership$war_baby_out_of_total_joiners, na.rm = TRUE),
             median(nazi_data_voting_and_joinership$prop_vote_1928),
             median(nazi_data_voting_and_joinership$prop_vote_1930),
             median(nazi_data_voting_and_joinership$change_votes),
             median(nazi_data_voting_and_joinership$total_tb_death_1914, na.rm = TRUE),
             median(nazi_data_voting_and_joinership$total_tb_death_1918, na.rm = TRUE),
             median(nazi_data_voting_and_joinership$ratio_mort_tb, na.rm = TRUE)),

  s.d. = c(sd(nazi_data_voting_and_joinership$total_joiners_per_1000, na.rm = TRUE),
           sd(nazi_data_voting_and_joinership$war_baby_joiners_per_1000, na.rm = TRUE),
           sd(nazi_data_voting_and_joinership$war_baby_out_of_total_joiners, na.rm = TRUE),
           sd(nazi_data_voting_and_joinership$prop_vote_1928),
           sd(nazi_data_voting_and_joinership$prop_vote_1930),
           sd(nazi_data_voting_and_joinership$change_votes),
           sd(nazi_data_voting_and_joinership$total_tb_death_1914, na.rm = TRUE),
           sd(nazi_data_voting_and_joinership$total_tb_death_1918, na.rm = TRUE),
           sd(nazi_data_voting_and_joinership$ratio_mort_tb, na.rm = TRUE)),
  
  min = c(min(nazi_data_voting_and_joinership$total_joiners_per_1000, na.rm = TRUE),
          min(nazi_data_voting_and_joinership$war_baby_joiners_per_1000, na.rm = TRUE),
          min(nazi_data_voting_and_joinership$war_baby_out_of_total_joiners, na.rm = TRUE),
          min(nazi_data_voting_and_joinership$prop_vote_1928),
          min(nazi_data_voting_and_joinership$prop_vote_1930),
          min(nazi_data_voting_and_joinership$change_votes),
          min(nazi_data_voting_and_joinership$total_tb_death_1914, na.rm = TRUE),
          min(nazi_data_voting_and_joinership$total_tb_death_1918, na.rm = TRUE),
          min(nazi_data_voting_and_joinership$ratio_mort_tb, na.rm = TRUE)),
  
  max = c(max(nazi_data_voting_and_joinership$total_joiners_per_1000, na.rm = TRUE),
          max(nazi_data_voting_and_joinership$war_baby_joiners_per_1000, na.rm = TRUE),
          max(nazi_data_voting_and_joinership$war_baby_out_of_total_joiners, na.rm = TRUE),
          max(nazi_data_voting_and_joinership$prop_vote_1928),
          max(nazi_data_voting_and_joinership$prop_vote_1930),
          max(nazi_data_voting_and_joinership$change_votes),
          max(nazi_data_voting_and_joinership$total_tb_death_1914, na.rm = TRUE),
          max(nazi_data_voting_and_joinership$total_tb_death_1918, na.rm = TRUE),
          max(nazi_data_voting_and_joinership$ratio_mort_tb, na.rm = TRUE))
)
summary_stats
```
